/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iss.examsys.ejb;

import com.iss.examsys.entity.ExamPaper;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

/**
 *
 * @author MA
 */
@Stateless
public class ExamPaperBean {
    @PersistenceContext EntityManager em;

    public void create(ExamPaper entity){
        em.persist(entity);
    }
    
    public void edit(ExamPaper entity) {
        em.merge(entity);
    }
    
    public void remove(ExamPaper entity) {
        em.remove(em.merge(entity));
    }
    
    public ExamPaper findById(Long id){        
        ExamPaper entity = em.find(ExamPaper.class, id);        
        return entity;
    }
    
    public List<ExamPaper> findAll(){
        TypedQuery<ExamPaper> result = em.createNamedQuery("ExamPaper.findAll", ExamPaper.class);        
        return result.getResultList();
    } 
    
    public List<ExamPaper> findByName(String name){
        TypedQuery<ExamPaper> result = em.createNamedQuery("ExamPaper.findByName", ExamPaper.class);
        result.setParameter("name", name);
        return result.getResultList();
    }
    
    public List<ExamPaper> findByModuleIds(List<Long> moduleIds){
        TypedQuery<ExamPaper> result = em.createNamedQuery("ExamPaper.findByModuleIds", ExamPaper.class);
        result.setParameter("moduleIds", moduleIds);
        return result.getResultList();
    }
}
